package com.example.androidtest;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

/**
 * @author ZhengL!
 * @fileName MainActivity.java
 * @data 2022/2/21/10:58
 * @description
 * @TODO
 * @email 420498246@qq.com
 */
public class MainActivity extends AppCompatActivity {

    private  ImageView imageView = null;
    private  Button button7 = null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //按钮提醒方式
//         Button button1 = (Button) findViewById(R.id.button1);
//         button1.setOnClickListener(new View.OnClickListener() {
//             @Override
//             public void onClick(View v) {
//                 Toast.makeText(MainActivity.this,"you clicked Button 1",
//                         Toast.LENGTH_SHORT).show();
//             }
//         });

        //Toast
        Button button1 = (Button)findViewById(R.id.button1);
        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Toast.makeText(MainActivity.this,"You clicked Butoon1",Toast.LENGTH_LONG).show();


            }
        });



        //按钮2  销毁
        Button button2 = (Button)findViewById(R.id.button2);
        button2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        //按钮3 显示 intent
       Button button3 = (Button)findViewById(R.id.button3);
       button3.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {
               //传入两个参数 参数1：上下文    参数2：活动目标
//             Intent intent =  new Intent(MainActivity.this,SecondMainActivity.class);
//
//
//             startActivity(intent);
               //匿名对象
               startActivity(new Intent(MainActivity.this, SecondMainActivity.class));
           }
       });

       //按钮4 隐式 intent
        Button button4 = (Button)findViewById(R.id.button4);
        button4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent("com.example.androidtest.ACTION_START");
                //增加了一个  Category
                intent.addCategory("com.example.androidtest.MY_CATEGORY");
                startActivity(intent);
            }
        });

        //跳转网站
        Button button5 =  (Button)findViewById(R.id.button5);
        button5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               Intent intent =  new Intent(Intent.ACTION_VIEW);
               intent.setData(Uri.parse("http://www.baidu.com"));
               startActivity(intent);

            }
        });

        //打电话
        Button button6 = (Button)findViewById(R.id.button6);
        button6.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Intent.ACTION_DIAL);
                intent.setData(Uri.parse("tel:13789564171"));
                startActivity(intent);
            }
        });










        //webView
        WebView webView = (WebView) findViewById(R.id.web_view);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.setWebViewClient(new WebViewClient());
        webView.loadUrl("http://www.baidu.com");

    }


    //退出  //退出程序  dialog
    public void  onDialogClick(View v){
          new AlertDialog.Builder(MainActivity.this)
                  .setIcon(android.R.drawable.ic_dialog_alert)
                  .setTitle("注意")
                  .setMessage("确定要退出吗？")
                  .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialog, int which) {
                          finish();
                      }
                  })
                  .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialog, int whichButton) {

                      }
                  }).create().show();
    }




    //重写了菜单的方法
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main,menu);
        return true;
    }

    //可以实际应用
    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        switch (item.getItemId()){
            case R.id.add_item:
                Toast.makeText(this,"You clicked Add",Toast.LENGTH_SHORT).show();
                break;
            case R.id.remove_itm:
                Toast.makeText(this,"You clicked Remove",Toast.LENGTH_SHORT).show();
                break;
            default:
        }
        return true;
    }
}